﻿package com.tudou.home.view
{
    import com.tudou.home.consts.*;
    import com.tudou.home.utils.*;
    import com.tudou.skin.*;
    import com.tudou.track.*;
    import flash.display.*;
    import flash.events.*;
    import org.puremvc.as3.patterns.mediator.*;

    public class ViewMediator extends Mediator
    {
        private var _privacyPanelSpace:Sprite;
        private var _background:Sprite;
        private var _placardAdSpace:Sprite;
        private var _bgAdSpace:Sprite;
        private var _playerSpace:Sprite;
        private var viewBox:Sprite;
        private var _miniSpace:Sprite;
        private var _loadingAdSpace:Sprite;
        public static const NAME:String = "ViewMediator";

        public function ViewMediator(param1:Sprite)
        {
            super(NAME, param1);
            viewBox = param1;
            init();
            initListener();
            return;
        }// end function

        private function stageMouseDownHandler(event:MouseEvent) : void
        {
            if (isNaN(event.stageX))
            {
                return;
            }
            AOPTracker.getInst().addNodeLog(NodeLog.PLAYER_CLICK, [int(event.stageX), int(event.stageY)]);
            return;
        }// end function

        public function get loadingAdSpace() : Sprite
        {
            return _loadingAdSpace;
        }// end function

        public function setAdBg(param1:DisplayObject) : void
        {
            if (_bgAdSpace)
            {
                _bgAdSpace.addChild(param1);
            }
            return;
        }// end function

        private function init() : void
        {
            _background = new BlackBackgroundMC();
            _bgAdSpace = new Sprite();
            _miniSpace = new Sprite();
            _playerSpace = new Sprite();
            _loadingAdSpace = new Sprite();
            _placardAdSpace = new Sprite();
            _privacyPanelSpace = new Sprite();
            viewBox.addChild(_background);
            viewBox.addChild(_bgAdSpace);
            viewBox.addChild(_miniSpace);
            viewBox.addChild(_playerSpace);
            viewBox.addChild(_loadingAdSpace);
            viewBox.addChild(_placardAdSpace);
            viewBox.addChild(_privacyPanelSpace);
            Binding.add(BindingConst.CHANGE_COLOR, this, setBackgroundColor);
            return;
        }// end function

        public function get privacyPanelSpace() : Sprite
        {
            return _privacyPanelSpace;
        }// end function

        public function setAdPlacard(param1:DisplayObject) : void
        {
            if (_placardAdSpace)
            {
                _placardAdSpace.addChild(param1);
            }
            return;
        }// end function

        public function get bgAdSpace() : Sprite
        {
            return _bgAdSpace;
        }// end function

        private function setBackgroundColor(param1:uint) : void
        {
            if (viewBox.contains(_background))
            {
                viewBox.removeChild(_background);
            }
            if (param1 == 0)
            {
                _background = new BlackBackgroundMC();
            }
            else
            {
                _background = new WhiteBackgroundMC();
            }
            viewBox.addChildAt(_background, 0);
            return;
        }// end function

        private function initListener() : void
        {
            viewBox.stage.addEventListener(MouseEvent.MOUSE_DOWN, stageMouseDownHandler);
            return;
        }// end function

        public function get playerSpace() : Sprite
        {
            return _playerSpace;
        }// end function

        public function goTransform(param1:uint, param2:uint, param3:Boolean) : void
        {
            _background.width = param1;
            _background.height = param2;
            _background.visible = !param3;
            return;
        }// end function

        public function removeAdBg() : void
        {
            if (_bgAdSpace)
            {
                while (_bgAdSpace.numChildren > 0)
                {
                    
                    _bgAdSpace.removeChildAt(0);
                }
            }
            return;
        }// end function

        public function get placardAdSpace() : Sprite
        {
            return _placardAdSpace;
        }// end function

        public function get miniSpace() : Sprite
        {
            return _miniSpace;
        }// end function

        public function removeAdPlacard() : void
        {
            if (_placardAdSpace)
            {
                while (_placardAdSpace.numChildren > 0)
                {
                    
                    _placardAdSpace.removeChildAt(0);
                }
            }
            return;
        }// end function

    }
}
